package com.ruoyi.web;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.framework.web.service.MyTokenService;
import com.ruoyi.system.domain.Hr;
import com.ruoyi.system.domain.Job;
import com.ruoyi.system.domain.JobSeekerRelation;
import com.ruoyi.system.service.ICompanyService;
import com.ruoyi.system.service.IHrService;
import com.ruoyi.system.service.IJobSeekerRelationService;
import com.ruoyi.system.service.IJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.prefs.BackingStoreException;

@RestController
public class SeekerprocessofapplicationController extends BaseController {
    @Autowired
    private IJobSeekerRelationService jobSeekerRelationService;
    @Autowired
    private IJobService jobService;
    @Autowired
    private MyTokenService myTokenService;
    @Autowired
    private ICompanyService companyService;
    @Autowired
    private IHrService hrService;
    @RequestMapping("/showseekerprogressofapplication")
    public List<Map<String,String>> showseekerprogressofapplication(@RequestParam("token")String token){
        //seeker的id
        Long seekerid = myTokenService.getloginid(token);
        JobSeekerRelation jobSeekerRelation = new JobSeekerRelation();
        jobSeekerRelation.setSeekerId(seekerid);
        //获取需要的记录个数
        List<JobSeekerRelation> resultllist=jobSeekerRelationService.selectJobSeekerRelationList(jobSeekerRelation);
        //返回的结果list
        List<Map<String,String>>info = new ArrayList<Map<String,String>>();
        for (int i = 0; i < resultllist.size(); i++) {
            //对于每一个记录
            //搞一个HashMap{}
            Map<String,String>infodetail = new HashMap<>();
            //放入需要的信息到HashMap{"relationId","1"}
            infodetail.put("relationId",resultllist.get(i).getRelationId().toString());
            //放入{"hrid":"1"}
            infodetail.put("hrid",resultllist.get(i).getHrId().toString());
            Hr hr = hrService.selectHrByHrId(resultllist.get(i).getHrId());
            infodetail.put("companyname",companyService.selectCompanyByCompanyId(hr.getCompanyId()).getCompanyName());
            infodetail.put("seekerid",seekerid.toString());
            infodetail.put("jobId",resultllist.get(i).getJobId().toString());


            infodetail.put("cvResult",(resultllist.get(i).getCvResult().equals("0")?"待审核":(resultllist.get(i).getCvResult().equals("1")?"同意":"拒绝")));
            Job job = jobService.selectJobByJobId(resultllist.get(i).getJobId());

            infodetail.put("jobname",job.getJobName());
            infodetail.put("jobupdatedate",job.getJobInfoupdatetime());
            infodetail.put("jobPoststat",job.getJobPoststat());


            //把这个map放到list中[{"hrid":1...}]
            info.add(infodetail);
        }
        return info;

    }
}
